package com.thread;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;



import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.swt.SWTResourceManager;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.bean.PassengerBean;
import com.bean.QueryUserBean;
import com.bean.SelectTrainBean;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.https.HttpHeader;
import com.https.UrlConstants;
import com.ui.MainWindow;
import com.utilities.SimplePlayer;
import com.utilities.TicketCode;
import com.utilities.TicketHelper;
import com.utilities.TimeUtils;

/**
* @ClassName: RunThread
* @Description: TODO
* @author alterhu2020@gmail.com
* @date Feb 15, 2014 9:27:30 PM
* 
*/

public class RunThread extends Thread {

	private static Logger logger=Logger.getLogger(RunThread.class);
	private QueryUserBean query;
	private MainWindow window;
	
	private static boolean bookok=false;

	
	
	
	
	public RunThread(QueryUserBean query,MainWindow window) {
		// TODO Auto-generated constructor stub
		this.query=query;
		this.window=window;
	}


	@Override
	public void run() {
		// TODO Auto-generated method stub
		String from=query.getFrom();
		String to=query.getTo();
		String traindate=query.getTraindate();
		String strTicketType=query.getStrTicketType();
		
		//window.cookies.clear();
		//window.getCookie(window.cookies, from, to, traindate);
		//window.logger("本次查询的Cookies 是："+window.cookies.toString());
		
		
		String fromCode = TicketHelper.getCityCode(TicketHelper.convertStation(from));
		String toCode = TicketHelper.getCityCode(TicketHelper.convertStation(to));
		
		Multimap<String, String> params= LinkedListMultimap.create();
		params.put("leftTicketDTO.train_date",traindate);
		params.put("leftTicketDTO.from_station",fromCode);
		params.put("leftTicketDTO.to_station",toCode );
		params.put("purpose_codes", strTicketType);
		
		
		
		List<String> trainnumbers=query.getTrainno();
		List<String> traintype=query.getTraintype();
		List<PassengerBean> selectedpassengers=query.getPassengers();
		
		
		TicketCode ticketcode=new TicketCode();
		
		String currentdate=null;
		try {
			currentdate=TimeUtils.getTrainDate(traindate);
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		logger.info("开始进行抢票了进行while循环进行判断票是否有?");
		int retrytime=0;
		while(!bookok){//如果没有预定成功的话
			    retrytime=retrytime+1;
			    window.logger("现在开始第"+retrytime+"次进行预订车票，车票信息是：从"+from+"到"+to+" 的火车，出发时间为："+traindate+",正在尝试查询余票然后预订。。。");
				window.isrunthread=true;
				if(window.isstopped){
					window.isrunthread=false;
					window.isstopped=false;
					window.logger("已经进入运行的run线程中，判断isstopped 是true,停止线程成功!");
					break;				
				}
				//查询余票信息是否有有对应的车次的
			   window.logger("开始预订操作。。。");
			   boolean findTicket=false;
			   String queryticket=null;
			   
			   
			   String secretStr=null;
			   String station_train_code=null;
			   String canwebbuy=null;
			   String seat_types_code=null;
			   String start_station_telecode=null;
			   String end_station_telecode=null;
			   String train_no=null;
			   String yp_info=null;
			   String location_code=null;
			   String selectedseatcode=null;
			   
			   
			   
			   
				try{
					queryticket= window.client.getRequest(UrlConstants.URL_SEARCH, params, HttpHeader.tiketSearch(), window.cookies);
					if(queryticket==null){
						window.logger("很抱歉，按您的查询条件，当前未找到从"+query.getFrom()+"到"+query.getTo()+" 的列车。您可以使用出行向导中的中转查询功能 查询换乘车次。");
						window.isrunthread=false;
						window.isstopped=false;
						break;
					}
				}catch(Exception queryexception){
					window.logger("查询对应的列车的车票信息错误："+from+"到"+to+",列车出发时间是："+traindate);
				}
				
			   //对列车信息进行逐个查询找到对应的车次就预订了
				JSONObject alldata=JSONObject.fromObject(queryticket);
			    JSONArray arraydata=alldata.getJSONArray("data");
			    int foundtrainnumber=arraydata.size();
			    for(int k=0;k<foundtrainnumber;k++){
			    	if(findTicket){
			    		 window.logger("第"+retrytime+"次预订,已经查到了余票列表中列车有票，马上进行预订操作.");
			    		 break;
			    	}
			    	
			    	JSONObject everytraindata=  arraydata.getJSONObject(k);
			    	secretStr=everytraindata.getString("secretStr");
			    	//secretStr=URLDecoder.decode(secretStr,"UTF-8");;
			    	JSONObject leftnewDTO=everytraindata.getJSONObject("queryLeftNewDTO");	
			    	
			    	station_train_code=leftnewDTO.getString("station_train_code");
			    	canwebbuy=leftnewDTO.getString("canWebBuy");
			    	//seat_types=leftnewDTO.getString("seat_types");
			    	start_station_telecode=leftnewDTO.getString("start_station_telecode");
			    	end_station_telecode=leftnewDTO.getString("end_station_telecode");
			    	train_no=leftnewDTO.getString("train_no");
			    	//String station_train_code=leftnewDTO.getString("station_train_code");
			    	
			    	yp_info=leftnewDTO.getString("yp_info");
		    		location_code=leftnewDTO.getString("location_code");
		    		
		    		window.logger("第"+retrytime+"次查询遍历列车，现在查的列车号是："+station_train_code+",是否可网上预订："+canwebbuy+"，进一步判断是否可以现在预订？");
		    		if(trainnumbers.size()!=0&&traintype.size()==0){
		    			window.logger("当前你设置的预选列车不为空，而座位类型为空，所以我们选择你设置的列车号，随机选择一个任意的座位类型");
		    			//遍历列的座位类型
		    			boolean foundtrain=false;
		    			for(int trainindex=0;trainindex<trainnumbers.size();trainindex++){
		    				 if(foundtrain){
		    					 window.logger("第"+retrytime+"次预订,已经查到了余票列表的车票,列车："+train_no+"，座位类型代码："+seat_types_code);
		    					 break;
		    				 }
		    				 String selectedtrainno=trainnumbers.get(trainindex);
		    				 if(station_train_code.equals(selectedtrainno)){  //find the ticket			    				   		    					 
			    					 for(String key:ticketcode.seattype.keySet())	{
						    				String seatenumber=leftnewDTO.getString(key);
						    				String temptypecode=ticketcode.seattype.get(key);
						    				
						    				 if((!seatenumber.equals("--"))&&(!seatenumber.equals("无"))&&(canwebbuy.equals("Y"))){
						    					 System.out.println("找到的对应车票的，对应的列车座位信息："+seatenumber+"\n"+temptypecode);
						    					 window.logger("找到的对应车票的，对应的列车座位信息："+seatenumber+"，"+temptypecode);
									    			
						    					 seat_types_code=temptypecode;
						    					 foundtrain=true;
						    					 findTicket=true;
						    					 break;
						    				 }
						    			} 	 		
		    				 }
		    			}
		    			if(!foundtrain){
		    				window.logger("根据你设置的订票条件，没能查到对应的列车的车票，请换个条件再来抢票吧！");
		    			}
		    			
		    			
		    		}else if(trainnumbers.size()==0&&traintype.size()==0){
		    			boolean findseat=false;
		    			window.logger("根据你当前的设置不用考虑列车的车次和列车的座位类型，只要有票我们就买额。");
		    			for(int seateindex=0;seateindex<traintype.size();seateindex++){		    				
		    				 if(findseat){
		    					 window.logger("第"+retrytime+"次预订,已经查到了余票列表的车票,列车："+train_no+"，座位类型代码："+seat_types_code);
		    					 break;
		    				 }
		    				 String traintypename=traintype.get(seateindex);
		    				 selectedseatcode=leftnewDTO.getString(traintypename);  //select seat number
		    				 String tempseate=ticketcode.seattype.get(traintypename);
		    				// System.out.println("火车车票座位类型名称："+traintypename+",\n"+"已经得到的车票座位类型Map为："+tempseate);
		    					
		    				 if((!selectedseatcode.equals("--"))&&(!selectedseatcode.equals("无"))&&(canwebbuy.equals("Y"))){  //find the ticket
		    					 //得到座位类型
		    					// String train_type_num=traintype.get(seateindex).split("_")[0];
		    					 System.out.println("找到的对应车票的，对应的列车座位信息："+traintypename+"\n"+tempseate);
		    					 window.logger("找到的对应车票的，对应的列车座位信息："+traintypename+"，"+tempseate);
		    					 seat_types_code=tempseate;
		    					 findseat=true;
		    					 findTicket=true;
		    					 break;
		    				 }
		    			}
		    			if(!findseat){
		    				window.logger("当前你设置的预选列车和座位类型都为空，没有查询到座位类型的车票，抱歉，换个预订条件再来抢票吧！");
		    			}
		    		}else if(trainnumbers.size()==0&&traintype.size()!=0){

		    			window.logger("当前你设置的预选列车为空，座位类型也不为空，将预订你设定的列车和车票座位类型");
		    			boolean findseat=false;
		    			for(int seateindex=0;seateindex<traintype.size();seateindex++){		    				
		    				 if(findseat){
		    					 window.logger("第"+retrytime+"次预订,已经查到了余票列表的车票,列车："+train_no+"，座位类型代码："+seat_types_code);
		    					 break;
		    				 }
		    				 String traintypename=traintype.get(seateindex);
		    				 selectedseatcode=leftnewDTO.getString(traintypename);  //select seat number
		    				 String tempseate=ticketcode.seattype.get(traintypename);
		    				// System.out.println("火车车票座位类型名称："+traintypename+",\n"+"已经得到的车票座位类型Map为："+tempseate);
		    					
		    				 if((!selectedseatcode.equals("--"))&&(!selectedseatcode.equals("无"))&&(canwebbuy.equals("Y"))){  //find the ticket
		    					 //得到座位类型
		    					// String train_type_num=traintype.get(seateindex).split("_")[0];
		    					 System.out.println("找到的对应车票的，对应的列车座位信息："+traintypename+"\n"+tempseate);
		    					 window.logger("找到的对应车票的，对应的列车座位信息："+traintypename+"，"+tempseate);
		    					 seat_types_code=tempseate;
		    					 findseat=true;
		    					 findTicket=true;
		    					 break;
		    				 }
		    			}
		    			if(!findseat){
		    				window.logger("当前你设置的预选列车不为空，而座位类型不为空，没有查询到座位类型的车票，抱歉，换个预订条件再来抢票吧！");
		    			}
		    		}else{ //如果两个都不为空
		    			boolean findall=false;
		    			for(int trainindex=0;trainindex<trainnumbers.size();trainindex++){			    				
		    				if(findall){
		    					window.logger("第"+retrytime+"次预订,已经查到了余票列表的车票,列车："+train_no+"，座位类型代码："+seat_types_code);
		    					break;
		    				}
		    				String selectedtrain=trainnumbers.get(trainindex);
		    				if(station_train_code.equals(selectedtrain)){			    					
		    					for(int seateindex=0;seateindex<traintype.size();seateindex++){
		    						 String seatetypename=traintype.get(seateindex);
				    				 selectedseatcode=leftnewDTO.getString(seatetypename);  //select seat number
				    				 String temptypecode=ticketcode.seattype.get(seatetypename);
				    				// System.out.println("选择的车次座位为："+selectedseatcode+"\n"+temptypecode);
				    				 if((!selectedseatcode.equals("--"))&&(!selectedseatcode.equals("无"))&&(canwebbuy.equals("Y"))){  //find the ticket	
				    					 
				    					 System.out.println("找到的对应车票的，对应的列车座位信息："+selectedseatcode+"\n"+temptypecode);
				    					 window.logger("找到的对应车票的，对应的列车座位信息："+selectedseatcode+"，"+temptypecode);
				    					 seat_types_code=temptypecode;
				    					 findall=true;
				    					 findTicket=true;					 
				    					 break;
				    				 }
				    			}
		    					
		    				}
		    			}
		    			if(!findall){
		    			   window.logger("根据你设置的列车和座位类型，没有查询到预设的列车和座位类型的车票，抱歉，换个预订条件再去抢票吧！");
		    			}
			    	   
			    	}
			    	
			    }//for 
			    
			    if(findTicket){  //进行预订
			    	
			    	

					Map<String,String> passengerstr=getAutoPassengerStr(selectedpassengers,seat_types_code);
					String oldpassenger=passengerstr.get("old");
					String passengerticket=passengerstr.get("new");
					
					
			    	window.logger("已经找到了你需要的列车的车票了，车次号为："+station_train_code+",列车的座位类型短代码是："+seat_types_code+",列车出发地为："+from+" 到 "+to);
			    	logger.info("已经找到了你需要的列车的车票了，车次号为："+station_train_code+",列车的座位类型短代码是："+seat_types_code+",列车出发地为："+from+" 到 "+to);
					window.selectedtrain=new SelectTrainBean(secretStr,from,to,seat_types_code,start_station_telecode,end_station_telecode, train_no, station_train_code, yp_info,oldpassenger,passengerticket,location_code);
					
					//bookedtrain=new BookTrainBean(secretStr, from, to, seat_types_code, start_station_telecode, end_station_telecode, train_no, station_train_code, yp_info, location_code);
				    //预订订单
					
					try {
						logger.info("即将预定的车票的座位类型为："+seat_types_code+",得到的是："+window.selectedtrain.getSeate_type_code());
						String[] returntoken=submitOrder(secretStr,traindate,from,to,strTicketType,seat_types_code,oldpassenger,passengerticket);
						if(returntoken==null){
								window.isrunthread=false;
								window.isstopped=true;
								window.logger("提交订单的时候遇到了错误，返回了错误信息:null");
								
						}
					    window.longtoken=returntoken[1];
					 //   String shorttoken=returntoken[1];
					    
					    queryCount(currentdate,start_station_telecode,end_station_telecode,strTicketType,seat_types_code,
					    		train_no,station_train_code,yp_info);
					    
					     //产生验证码
					    generateConfirmCode();
					    window.logger("第"+retrytime+"次预订,已经查到了余票列表的车票,订单确认码已经为你生成，请你手工输入先，否则不能提交订单，难得啊，你抢到了票，麻利点输入验证码一步到位！....");
					    //播放声音，提示输入验证码
					    SimplePlayer.playClip("/com/images/message.wav");
					    bookok=true;
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						window.isrunthread=false;
						window.isstopped=true;
						window.logger("第"+retrytime+"次预订,没能预订余票列表的车票,列车："+train_no+"，座位类型代码："+seat_types_code+"，现在停止线程成功!");
						bookok=true;
					}
					
					//break;
			    }
			    
				
			/*
			 * {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":[
			
			 *      {"queryLeftNewDTO":
			 *      {"train_no":"24000K136309","station_train_code":"K1363","start_station_telecode":"BXP",
			 *      "start_station_name":"北京西","end_station_telecode":"CDW","end_station_name":"成都","from_station_telecode":"BXP",
			 *      "from_station_name":"北京西","to_station_telecode":"CDW","to_station_name":"成都","start_time":"22:15","arrive_time":"04:56",
			 *      "day_difference":"2","train_class_name":"","lishi":"30:41","canWebBuy":"Y","lishiValue":"1841",
			 *      "yp_info":"1022903267406400000010229003063040300000","control_train_day":"20201231","start_train_date":"20140215",
			 *      "seat_feature":"W3431333","yp_ex":"10401030","train_seat_feature":"3","seat_types":"1413","location_code":"P1",
			 *      "from_station_no":"01","to_station_no":"18","control_day":19,"sale_time":"0800","is_support_card":"0",
			 *      "gg_num":"--","gr_num":"--","qt_num":"--","rw_num":"无","rz_num":"--","tz_num":"--","wz_num":"有","yb_num":"--","yw_num":"无",
			 *      "yz_num":"有","ze_num":"--","zy_num":"--","swz_num":"--"},
			 *      "secretStr":"MjAxNC0wMi0xNSMwMCNLMTM2MyMzMDo0MSMyMjoxNSMyNDAwMEsxMzYzMDkjQlhQI0NEVyMwNDo1NiPljJfkuqzopb8j5oiQ6YO9IzAxIzE4IzEwMjI5MDMyNjc0MDY0MDAwMDAwMTAyMjkwMDMwNjMwNDAzMDAwMDAjUDEjMTM5MjQyOTA0NTI1MSNGMTdEOUUxMkIyNjE0RjI1QUQ3MDVDOTI2QkVFMUMzQkNERDQzRkI1MTU4MDhGQUU4NUY2Q0FCNg%3D%3D",
			 *      "buttonTextInfo":"预订"}
			 *      ,"messages":[],"validateMessages":{}}
			 */
			  
			
		} //while
		
		window.logger("预定车票订单线程结束！");
		
	}
	
	private String[] submitOrder(String secretStr,String traindate,String fromstationname,String tostationname,String strTicketType,String seat_types,String oldpassenger,String  passengerticket) throws KeyManagementException, NoSuchAlgorithmException, UnsupportedEncodingException{
		
		
		String[] tokenarray=null;
	
		
		Multimap<String, String> params= LinkedListMultimap.create();
		
	/*
	 * https://kyfw.12306.cn/otn/resources/merged/queryLeftTicket_end_js.js?scriptVersion=1.193
	 * getOldPassengersForAutoSubmit=function(){
	 * var bT="";
	 * for(var bS=0;bS<passengerChecked.length;bS++){
	 * var bR=passengerChecked[bS].passenger_name+","+passengerChecked[bS].passenger_id_type_code+","+passengerChecked[bS].passenger_id_no+","+passengerChecked[bS].passenger_type;
	 * bT+=bR+"_"
	 * }return bT}
	 */
		String decodestr=URLDecoder.decode(secretStr,"UTF-8");
		params.put("secretStr", decodestr);
		params.put("train_date", traindate);
		params.put("tour_flag", "dc");
		params.put("purpose_codes", strTicketType);
		params.put("query_from_station_name",fromstationname);
		params.put("query_to_station_name", tostationname);
		params.put(":", "");
		params.put("cancel_flag","2");
		params.put("bed_level_order_num","000000000000000000000000000000");
		params.put("passengerTicketStr", passengerticket);		
		params.put("oldPassengerStr",oldpassenger );
		
		
		//String longtoken=null;
		JSONArray message=null;
		try{			
			String datas = window.client.postRequest(UrlConstants.URL_AUTOSUBMITORDER, params, HttpHeader.submitOrder(), window.cookies);
			JSONObject ordermsg=JSONObject.fromObject(datas);
			message=ordermsg.getJSONArray("messages");
			System.out.println("提交后返回了错误信息是:"+message.toString());
			//		对不起，由于您取消次数过多，今日将不能继续受理您的订票请求！
			if(message!=null){
				JSONObject resultdata= ordermsg.getJSONObject("data");
				String resulttoken=resultdata.getString("result");
				//String resultstatus=resultdata.getString("submitStatus");
				if(resultdata!=null&&resulttoken!=null){
					tokenarray=resulttoken.split("#");
				}
			}
		}catch(Exception e){
			window.logger("预定改列车遇到了问题，返回错误信息："+message.toString());
		}
		//location_code
		//long token ,short token
		
		//{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":
		//{"result":"P1
		//            #D6DE7EB84F1BEA2C83594304FBBEAE004E1945C6955D3EF0BC398469
		//            #1022903267406400000010229003063040300000
		//            #1",
		//"submitStatus":true},"messages":[],"validateMessages":{}}
		return tokenarray;
		
	}
	
 private String queryCount(String currentdate,String fromtelecode,String totelecode,String strTicketType,String seattype,String trainno,String station_train_code,String ypinfo) throws KeyManagementException, NoSuchAlgorithmException{
		
        Multimap<String, String> params= LinkedListMultimap.create();
		
		params.put("_json_att", "");
		params.put("fromStationTelecode", fromtelecode);
		params.put("leftTicket", ypinfo);
		params.put("purpose_codes", strTicketType);
		params.put("seatType", seattype);
		params.put("stationTrainCode", station_train_code);
		params.put("toStationTelecode", totelecode);
		params.put("train_date", currentdate);
		params.put("train_no", trainno);
		String data=window.client.postRequest(UrlConstants.URL_GETQUEUECOUNT, params, HttpHeader.getQueueCountAsync(), window.cookies);
		JSONObject contentresult=JSONObject.fromObject(data);
		JSONObject ticketdata=contentresult.getJSONObject("data");
		String ticketid=ticketdata.getString("ticket");
		return ticketid;
		
	}
	
   public void generateConfirmCode() throws KeyManagementException, NoSuchAlgorithmException{
	   int codeindex=TimeUtils.randomnumber(100, 10000);
       String url=UrlConstants.URL_CONFIRM_PASSCODE+codeindex;
       window.client.getPassCode(url,window.confirm_image, HttpHeader.getPassCode(true), window.cookies);	
       Display.getDefault().asyncExec(new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			   SWTResourceManager.disposeImages();
			   window.lblNewLabel_refreshcode.setImage(SWTResourceManager.getImage(window.confirm_image));
			   window.lblNewLabel_refreshcode.redraw();
			   window.text_inputcode.setText("");
			   window.logger("成功生成了确认订单的验证码，请先手工输入，暂时不支持自动输入！");
		}
	});
     
	   
   }
	 

	public Map<String,String> getAutoPassengerStr(List<PassengerBean> selectedPassenger,String seatecode){
		
		
		/*
		 * https://kyfw.12306.cn/otn/resources/merged/queryLeftTicket_end_js.js?scriptVersion=1.193
		 * getOldPassengersForAutoSubmit=function(){
		 * var bT="";
		 * for(var bS=0;bS<passengerChecked.length;bS++){
		 * var bR=passengerChecked[bS].passenger_name+","+passengerChecked[bS].passenger_id_type_code+","+passengerChecked[bS].passenger_id_no+","+passengerChecked[bS].passenger_type;
		 * bT+=bR+"_"
		 * }return bT}
		 */
		
		/*
		 * getpassengerTicketsForAutoSubmit=function()
		 * {var bR="";
		 * for(var bS=0;bS<tickets_info.length;bS++)
		 * {var bT="";
		 * if("WZ"==tickets_info[bS].seat_type)
		 * {bT=ah(g())}
		 * else{bT=tickets_info[bS].seat_type}var bU=bT+",0,"+tickets_info[bS].ticket_type+","+tickets_info[bS].name+","+tickets_info[bS].id_type+","+tickets_info[bS].id_no+","+(tickets_info[bS].phone_no==null?"":tickets_info[bS].phone_no)+",N";
		 * bR+=bU+"_"}
		 * return bR.substring(0,bR.length-1)};
		 */
		
		Map<String,String> passengermap=new HashMap<String,String>();
		String oldpassenger="";
		String bookedpassengerticket="";
		logger.info("已经选择的乘客个数为："+selectedPassenger.size());
		for(PassengerBean singlepassenger:selectedPassenger){
			    
			     
			     String passengername=singlepassenger.getPassengername();
			     String passengertype=singlepassenger.getPassengertype();
			     String cardid= singlepassenger.getPassengercardid();
			     String cardtype=singlepassenger.getCardtype();
			     String passengerphone=singlepassenger.getPassengermobile();
			     
			     String tempoldpassenger= passengername +","+cardtype+ ","+ cardid + ","+passengertype;
			     oldpassenger+=tempoldpassenger+"_";
			   //  oldpassenger += oldpassenger + "_"; 
			     
			     String tempnewticket="";
			     
			     if(seatecode=="WZ"){  //无座的类型code
			    	 tempnewticket="WZ";
			     }else{
			    	 tempnewticket=seatecode;
			    	 //bookedpassengerticket=bookedpassengerticket+singlepassenger.getSeateType();
			     }
			     String temp2=tempnewticket+",0,"+passengertype+","+passengername+","+cardtype+","+cardid+","
			    		 +(passengerphone == null ? "" :passengerphone)+",N";
			     bookedpassengerticket+=temp2+"_";
			   
			     logger.info("得到对应的乘客的ticket字符串："+bookedpassengerticket);
			   //  bookedpassengerticket += bR +"_";
			    
		}
		bookedpassengerticket=bookedpassengerticket.substring(0, bookedpassengerticket.length() - 1);
		passengermap.put("old", oldpassenger);
		passengermap.put("new", bookedpassengerticket);
		return passengermap;
		
	}
	
	
}
